#include <RCSwitch.h>

RCSwitch mySwitch = RCSwitch();

#define SENDBUFFERSIZE 10
char sendBuffer[SENDBUFFERSIZE];
int serialTimeout = 200;

void resetBuffer() {
  for (int i=0; i<SENDBUFFERSIZE; i++) {
    sendBuffer[i] = 0;
  }
} 


void setup() {

  Serial.begin(9600);
  Serial.setTimeout(serialTimeout);
  Serial.flush(); 
  resetBuffer();

  // Transmitter is connected to Arduino Pin #10  
  mySwitch.enableTransmit(10);
}



void loop() {
  
  int received = Serial.readBytesUntil(0, sendBuffer, SENDBUFFERSIZE);
  if (received > 0)  {
    long code = strtol(sendBuffer, NULL, 10);
    mySwitch.send(code, 24);
    Serial.println(code);
    resetBuffer();
  }

}

